function nfixed = parseAsLatexMath(nin)
% nfixed = nin;
% [nextra,ind] = checkLatexMath(nin);
% nfixed(ind) = sub(nextra);
if isa(nin,'cell')
    nfixed = cellfun(@sub2,nin,'UniformOutput',false);
else
    nfixed = sub2(nin);
end
end

function so = sub2(si)
if isempty(si)
    assert('stop that')
end

% strsplit defaults to splitting by spaces, but for future-proofing, delimiter
% is specified anyway
pieces = cellfun(@fixund, strsplit(si, ' '), 'UniformOutput', false);
so = strjoin(pieces, ' ');

    function so = fixund(si)
        spl = strsplit(si, '_');
        n = numel(spl);
        if n > 1
            spl{2} = sprintf('%s_{%s}', spl{1}, spl{2});
            so = strjoin(spl(2:end), ' '); % note the use of (), not {}
        else
            so = si;
        end
    end
end





